<?php
include('conf.php');
if(isset($_GET['from'])&&$_GET['from']=='auth'){
    $ux="https://openapi.baidu.com/oauth/2.0/token";
    $ud=array(
    	"grant_type"=>"authorization_code",
		"code"=>$_GET['code'],
		"client_id"=>AK,
		"client_secret"=>SK,
		"redirect_uri"=>DM.'/auth/?from=auth'
    );
    $res = json_decode(Hpost($ux,$ud),true);
    $ress = array('access_token'=>$res['access_token']);
    $gcu = $_COOKIE['from'].'&auth='.base64_encode(json_encode($ress));
    header('Location:'.$gcu);
}else{
setcookie('from',$_GET['from']);
$gcu = "https://openapi.baidu.com/oauth/2.0/authorize?".
    "response_type=code&".
	"client_id=".AK."&".
	"redirect_uri=".urlencode(DM.'/auth/?from=auth')."&".
	"scope=basic,netdisk";
    header('Location:'.$gcu);
}
